/*
Look at market shares in a given year
- By entry quarter or month
- Look for temporal discontinuity
- Does it matter if it's not discontinuous? Natural diffusion process

For the big entry events, do 1 year, 3 year, and 5 year market shares by cohort
*/


set more off
clear
use user_quarter_choice_cholesterol


// focus on cholesterol
tab indic_id
keep if indic_id == 5

// need name for overlap analysis
merge m:1 generic_id using generic_name_mapping
keep if _merge == 3
drop _merge


gen first_use_quarter = quarter if first_use == 1
egen first_q = max(first_use_quarter), by(enrolid)

gen period = quarter - first_q



set scheme s1mono
graph set window fontface "Palatino Linotype"




/*
Lipitor (Figure 2A)
*/



preserve

gen lipitor = (gennme == "Atorvastatin Calcium") & generic == 0

keep if first_q != .
keep if first_q >= qofd(mdy(1,1,1996))

gen users = 1
collapse (mean) lipitor (count) users, by(first_q year)
sort first_q

gen date = dofq(first_q)
format date %td
local t = mdy(1,31,1997)

twoway (scatter lipitor date if year == 1997, msymbol(circle)) ///
(scatter lipitor date if year == 1999, msymbol(diamond)) ///
(scatter lipitor date if year == 2001, msymbol(triangle)), xline(`t') legend(label(1 "Z=1997") label(2 "Z=1999") label(3 "Z=2001") size(large) region(lwidth(none))) ytitle("Lipitor Market Share in Year Z", size(medlarge)) xtitle("Starting Cohort", size(medlarge))

graph save lipitor_twoway, replace
graph export lipitor_twoway.pdf, replace

restore






/*
CRESTOR (Figure 2B)
*/


preserve

gen crestor = (gennme == "Rosuvastatin Calcium")


keep if first_q != .
keep if first_q >= qofd(mdy(1,1,2000))

gen users = 1
collapse (mean) crestor (count) users, by(first_q year)
sort first_q

gen date = dofq(first_q)
format date %td
local t = mdy(8,12,2003)

twoway (scatter crestor date if year == 2004, msymbol(circle)) ///
(scatter crestor date if year == 2006, msymbol(diamond)) ///
(scatter crestor date if year == 2008, msymbol(triangle)), xline(`t') legend(label(1 "Z=2004") label(2 "Z=2006") label(3 "Z=2008") size(large) region(lwidth(none))) ytitle("Crestor Market Share in Year Z", size(medlarge)) xtitle("Starting Cohort", size(medlarge))

graph save crestor_twoway, replace
graph export crestor_twoway.pdf, replace

restore


